#include "newwin.h"
#include <QString>
#include <QDebug>
#include <QPushButton>
#include <QLineEdit>

int a=0;
int b=0;
NewWin::NewWin(QWidget *parent) : QWidget(parent)
{
    this->setWindowTitle("窗口2");
    QString s = windowTitle();
    qDebug()<<s;
        //qDebug会自动换行
    //this->resize(800,600);
        //设置窗口大小
    this->setFixedSize(1000,800);
    QPushButton *firstwin = new QPushButton;
    firstwin->setParent(this);
    firstwin->setText("返回窗口一");
    firstwin->resize(100,50);

    QLineEdit *mylineedit = new QLineEdit;
        //文本框组件
    mylineedit->setParent(this);
    mylineedit->resize(500,100);
    mylineedit->move(0,75);
    mylineedit->setText("");
    mylineedit->setFont(QFont("黑体", 16));
        //设置Font字体

    connect(firstwin, &QPushButton::clicked, [=](){
        emit this->mysignal2(666);
        mylineedit->setText("");
        //带参数，发送一个信号
    });

    QPushButton *myadd = new QPushButton;
    myadd->setParent(this);
    myadd->resize(100,50);
    myadd->move(0,200);
    myadd->setText("+");
    connect(myadd, &QPushButton::clicked, [=](){
        QString text1 = mylineedit->text();
        //get到文本框内容
        a=text1.toInt();
        //让全局变量a获取到QString->int的值
        mylineedit->setText("");
        //初始化文本框
    });

    QPushButton *mygetnum = new QPushButton;
    mygetnum->setParent(this);
    mygetnum->resize(100,50);
    mygetnum->move(150,200);
    mygetnum->setText("=");
    connect(mygetnum, &QPushButton::clicked, [=](){
        QString text2 = mylineedit->text();
        b=text2.toInt();
        //让全局变量b获取到QString->int的值
        mylineedit->setText(QString::number(a+b));
        //将a+b转成QString类型赋给文本框
        a=0;
        b=0;
        //a、b初始化
    });
}
